package com.turing.customer.controller;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.shaded.com.google.gson.JsonObject;
import com.turing.customer.entity.Customer;
import com.turing.customer.service.CustomerService;
import org.springframework.web.bind.annotation.*;
import result.Result;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;

/**
 * @author 孙国鹏
 */
@RestController
public class CustomerController {

    @Resource private CustomerService customerService;

    /**
     * 日活跃统计
     * @return
     */
    @GetMapping("statistics/liveDay")
    public Result liveDay(@RequestParam(value = "day", required = false) Date day){
        String day1 = new SimpleDateFormat("yyyy-MM-dd").format(day);
        return customerService.liveDay(day1);
    }

    /**
     * 月活跃统计
     * @RequestParam(value = "month", required = false) Date month
     * @RequestParam(value = "count", required = false) Integer count
     */
    @GetMapping("statistics/liveMonth")
    public Result liveMonth(@RequestParam(value = "month", required = false) Date month
     ,@RequestParam(value = "count", required = false) Integer count) throws ParseException {
        String mth = new SimpleDateFormat("yyyy-MM").format(month);
        return customerService.liveMonth(mth,count);
    }

    /**
     * 客户修改
     */
    @PatchMapping("cus/cusEdit")
    public Result cusEdit(@RequestBody JSONObject jsonObject){
        return customerService.cusEdit(jsonObject);
    }

    /**
     * 客户详情
     */
    @GetMapping("cus/geCusById")
    public Result geCusById(@RequestParam(value = "id", required = false) String id) {
        return customerService.geCusById(id);
    }

    /**
     * 客户列表
     */
    @GetMapping("cus/cusList")
    public Result cusList(
            @RequestParam(value = "cusNickname", required = false) String cusNickname,
            @RequestParam(value = "cusInfo", required = false) String cusInfo,
            @RequestParam(value = "sortType",required = false,defaultValue = "0") Integer sortType,
            @RequestParam(value = "orderType",required = false,defaultValue = "0") Integer orderType,
            @RequestParam(value = "pageNum", required = false) Integer pageNum,
            @RequestParam(value = "pageSize", required = false) Integer pageSize
    ){
        return customerService.cusList(cusNickname,cusInfo,sortType,orderType,pageNum,pageSize);
    }

    /**
     * 根据主键集合得到客户集合(手机)
     */
    @GetMapping("cus/cusListByCusIds")
    public Result cusListByCusIds(@RequestParam(value = "ids", required = false) String[] ids){
        System.out.println("ids = " + Arrays.toString(ids));
        return customerService.cusListByCusIds(ids);
    }

    /**
     * 个人中心(手机)
     */
    @GetMapping("cus/cusCenter")
    public Result cusCenter(@RequestParam(value = "cusId", required = false) String cusId,
                            @RequestParam(value = "concernState", required = false) Integer concernState){
        return customerService.cusCenter(cusId);
    }

    /**
     * 客户排行榜(手机)
     */
    @GetMapping("cus/rankList")
    public Result rankList(@RequestParam(value = "orderType", required = false) Integer orderType,
                           @RequestParam(value = "pageNum", required = false) Integer pageNum,
                           @RequestParam(value = "pageSize", required = false) Integer pageSize){
        return customerService.rankList(orderType,pageNum,pageSize);
    }

    /**
     * 我的钱包(手机)
     */
    @GetMapping("cus/myWallet")
    public Result myWallet(){
        return customerService.myWallet();
    }

    /**
     * 客户买单(手机)
     */
    @PostMapping("cus/cusPay")
    public Result cusPay(@RequestBody JSONObject jsonObject) throws ParseException {
        return customerService.cusPay(jsonObject);
    }

    /**
     * 增加/取消关注(手机)
     */
    @PostMapping("concern/cnSave")
    public Result cnSave(@RequestParam(value = "cusId", required = false) String cusId){
        return customerService.cnSave(cusId);
    }

    /**
     * 我的粉丝列表(手机)
     */
    @GetMapping("concern/likeList")
    public Result likeList(@RequestParam(value = "cusId", required = false) String cusId,
                           @RequestParam(value = "pageNum", required = false) Integer pageNum,
                           @RequestParam(value = "pageSize", required = false) Integer pageSize){
        return customerService.likeList(cusId,pageNum,pageSize);
    }

}
